﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'rightFindByRole')
	BEGIN
		DROP  Procedure  rightFindByRole
	END
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[rightFindByRole]
	-- Add the parameters for the stored procedure here
	@role_name VARCHAR(50), 
	@app_id INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @rol_id INT;

	SELECT @rol_id = lit_rol_id
	FROM lit_rol
	WHERE lit_rol_nombre = @role_name
	AND lit_aplicacion_id = @app_id;

    -- Insert statements for procedure here
	SELECT *
	FROM lit_privilegio p 
	JOIN lit_rol_privilegio rp ON p.lit_privilegio_id = rp.lit_privilegio_id
	WHERE rp.lit_rol_id = @rol_id;
END
GO